% collect GPS and UWB data simultaneously

% file prefix for experiment data
fileprefix = 'anchor1_10cm';

gpsbase = 'com11';
gpsagent= 'com8';
uwbagent= 'com9';

delete(instrfindall);
serialuwbagent=serial(uwbagent);                                     
set(serialuwbagent,'BaudRate',115200,'StopBits',1,'Parity','none','DataBits',8,'InputBufferSize',8000);
fopen(serialuwbagent);

serialgpsbase=serial(gpsbase);                                     
set(serialgpsbase,'BaudRate',115200,'StopBits',1,'Parity','none','DataBits',8,'InputBufferSize',8000);
fopen(serialgpsbase);

serialgpsagent=serial(gpsagent);                                     
set(serialgpsagent,'BaudRate',115200,'StopBits',1,'Parity','none','DataBits',8,'InputBufferSize',8000);
fopen(serialgpsagent);

funlist = {@uwbread,@gpsread,@gpsread};
datalist= {serialuwbagent,serialgpsbase,serialgpsagent};
outputlist = cell(3,1);

parfor i=1:3
    outputlist{i}=funlist{i}(datalist{i});
end
save(strcat(fileprefix,'_',num2str(round(now*1e6)),'.mat'));